package com.team.sion.controller;

import com.team.sion.common.ErrorMessage;
import com.team.sion.common.SuccessMessage;
import com.team.sion.pojo.Admin;
import com.team.sion.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    // 登录
    @RequestMapping("/login/status")
    public Object login(@RequestParam String name,
                        @RequestParam String password){
        Admin admin = new Admin();
        admin.setPassword(password);
        admin.setName(name);
        List<Admin> list = adminService.findAdmin(admin);
        if(list.size() != 0){
            return new SuccessMessage<List<Admin>>("登录成功", list).getMessage();
        }else{
            return new ErrorMessage("用户名或密码错误").getMessage();
        }
    }

}
